<%--
  Created by IntelliJ IDEA.
  User: xdd
  Date: 2022/7/19
  Time: 13:49
  To change this template use File | Settings | File Templates.
--%>
<!--1.指令  环境设置-->
<%@ page import="java.util.List,java.util.ArrayList"
         contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="cn.bdqn.news.entity.User" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>

<!--2.声明  写属性和方法-->
<%!
    private String name = "张三";  //属性
    public String show(String content){
        return content;
    }

%>
<!--3.小脚本  流程控制 变量声明 -->
<%
    int age =20;   //局部变量
    if(100 > 0){
       String info = show("hello JSP");
        System.out.println("info:"+info);
    }
%>
<!--4.表达式 显示数据到页面 -->
<%=1+1%>
<%=name%>
<%=show("jsp")%>
<!--5.注释 -->
<%--java注释--%>

<html>
<head>
    <title>Title</title>
    <%
        String[] colors = {"red","blue","yellow"};
        String  color = colors[(int)(Math.random() * colors.length)];
    %>
    <style type="text/css">
        span{
            color: <%=color%>>;
        }
    </style>
</head>
<body>
<P>姓名:<%=name%></P>
<%
    // 模拟用户列表
    List<User> userList = new ArrayList<User>();
    for(int i = 1;i <= 20;i++){
        User user = new User();
        user.setUid(i);
        user.setUname("user"+i);
        user.setUpwd("123456");
        user.setUrole(1);
        userList.add(user);
    }
%>
<!--JSP显示Java数据-->
<ul>
    <%
        for (User user : userList){
    %>
        <li><span><%=user.getUname()%></span>
        <input type="text" value="<%=user.getUpwd()%>">
        </li>
    <%
        }
    %>
</ul>
<%
    int num = 300;
    String role = "管理员";
%>
<!--JS显示Java数据-->
<script type="text/javascript">
    var num = <%=num%>
    alert(num);
    var role = "<%=role%>";
    alert(role);
</script>
</body>
</html>
